﻿/* ============================================================================
(c) Copyright 2012 Hewlett-Packard Development Company, L.P.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights to
use, copy, modify, merge,publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
============================================================================ */
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;

namespace HPCloud.Objects.Domain
{
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.1")]
    [System.Xml.Serialization.XmlTypeAttribute("container")]

    public class StorageLocation
    {
        private StoragePath _storagePath;
        private StorageObject _storageObject;

        public StoragePath StoragePath
        {
            get { return _storagePath; }
            set { _storagePath = value; }
        }
        public StorageObject StorageObject
        {
            get { return _storageObject; }
            set { _storageObject = value; }
        }
    }

    public partial class StorageLocations
    {
        private string typeField;
        private bool _marker = false;
        private List<StorageLocation> _list = new List<StorageLocation>();
        private List<CommonPrefixes> _folderNames = new List<CommonPrefixes>();

        #region Ctors
//===========================================================================================================
/// <summary>
/// 
/// </summary>
//===========================================================================================================
        public StorageLocations()
        { }
        #endregion
//===========================================================================================================
/// <summary>
/// 
/// </summary>
/// <returns></returns>
//===========================================================================================================
        public List<StorageLocation> GetLocations()
        {
            return _list;
        }
//===========================================================================================================
/// <summary>
/// 
/// </summary>
/// <returns></returns>
//===========================================================================================================
        public List<StorageObject> GetFiles()
        {
            var storageLocations =
            from storageLocation in _list
            where storageLocation.StorageObject.ObjectType == "File"
            select storageLocation.StorageObject;
            
            return storageLocations.ToList();
        }
//===========================================================================================================
/// <summary>
/// 
/// </summary>
/// <returns></returns>
//===========================================================================================================
        public List<StorageObject> GetFolders()
        {
            var storageLocations =
            from storageLocation in _list
            where storageLocation.StorageObject.StorageObjectType == StorageObjectType.Folder
            select storageLocation.StorageObject;

            return storageLocations.ToList();
        }
        #region Properties
//===========================================================================================================
/// <summary>
/// No files or Folders exist in the set..
/// </summary>
//===========================================================================================================
        public bool IsEmpty
        {
            get
            {
                if (this.List == null || this._folderNames == null || _folderNames.Count == 0)
                    return true;
                else
                    return false;
            }
        }
//===========================================================================================================
/// <summary>
/// 
/// </summary>
//===========================================================================================================
        public bool HasFiles
        {
            get
            {
                if (this.List == null)
                {
                    return false;
                }
                else
                {
                    return true;
                }
            }
        }
//===========================================================================================================
/// <summary>
/// 
/// </summary>
//===========================================================================================================
        public bool HasFolders
        {
            get
            {
                if (this.GetFolders().Count > 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
        }
//===========================================================================================================
/// <summary>
/// 
/// </summary>
//===========================================================================================================
        [System.Xml.Serialization.XmlElementAttribute("object")]
        public List<StorageLocation> List
        {
            get
            {
                return _list;
            }
            set
            {
                _list = value;
            }
        }
//===========================================================================================================
/// <summary>
/// 
/// </summary>
/// <param name="storagePath"></param>
/// <param name="storageObject"></param>
//===========================================================================================================
        public void Add(StoragePath storagePath, StorageObject storageObject)
        {
            StorageLocation location = new StorageLocation();
            location.StorageObject   = storageObject;
            location.StoragePath     = storagePath;

            _list.Add(location);
        }
//===========================================================================================================
/// <summary>
/// 
/// </summary>
/// <returns></returns>
//===========================================================================================================
        public List<StorageLocation> ToList()
        {
            return _list;
        }
        #endregion
    }
}
